//
//  VSFindGiftPushCollectionViewCell.m
//  UI项目2.0
//
//  Created by dlios on 15/7/17.
//  Copyright (c) 2015年 星际科技. All rights reserved.
//

#import "VSFindGiftPushCollectionViewCell.h"
#import "VSFrameGrand.h"
#import "UIImageView+WebCache.h"
#import "VSFindOtherPushViewController.h"
@implementation VSFindGiftPushCollectionViewCell

- (void)dealloc
{
    [_MainImageView release];
    [_MainLabel release];
    [_GiftCellbackGroundView release];
    [_GiftPushJumpButton release];
    [_GiftPushWireLabel release];
    [_GiftPushMoneyLabel release];
    [_GiftPushTaobaoImageView release];
    [_GiftPassModel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.GiftCellbackGroundView = [[[UIImageView alloc]init]autorelease];
        self.GiftCellbackGroundView.userInteractionEnabled = YES;
        [self.contentView addSubview:self.GiftCellbackGroundView];
        
        self.MainImageView = [[[UIImageView alloc]init]autorelease];
        [self.GiftCellbackGroundView addSubview:self.MainImageView];
        self.MainImageView.userInteractionEnabled = YES;
        
        self.MainLabel = [[[UILabel alloc]init] autorelease];
        self.MainLabel.numberOfLines = 0;
        [self.GiftCellbackGroundView addSubview:self.MainLabel];
        self.MainLabel.backgroundColor = [UIColor clearColor];
        
        self.GiftPushJumpButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.GiftCellbackGroundView addSubview:self.GiftPushJumpButton];
        
        
        self.GiftPushWireLabel = [[[UILabel alloc]init]autorelease];
        [self.GiftCellbackGroundView addSubview:self.GiftPushWireLabel];
        self.GiftPushWireLabel.backgroundColor = [UIColor lightGrayColor];
        self.GiftPushWireLabel.alpha = 0.7;
        
        self.GiftPushTaobaoImageView = [[[UIImageView alloc]init]autorelease];
        [self.GiftCellbackGroundView addSubview:self.GiftPushTaobaoImageView];
        
        
        self.GiftPushMoneyLabel = [[[UILabel alloc]init]autorelease];
        [self.GiftCellbackGroundView addSubview:self.GiftPushMoneyLabel];
        
        self.GiftPresentToOther = [UIButton buttonWithType:UIButtonTypeCustom];
        self.GiftPresentToOther.backgroundColor = [UIColor clearColor];
        [self.MainImageView addSubview:self.GiftPresentToOther];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.GiftCellbackGroundView.frame = layoutAttributes.bounds;
    _TextHeight = layoutAttributes.frame.size.height;
    _TextWidth = layoutAttributes.frame.size.width;
}

- (void)setModel:(VSFindGiftModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    _MainLabel.font = [UIFont systemFontOfSize:18];
    _MainImageView.frame = CGRectMake(0, 0, _TextWidth, _TextWidth / [[model.photo objectForKey:@"width"] floatValue] * [[model.photo objectForKey:@"height"] floatValue]);
    _MainLabel.frame = CGRectMake(8, self.MainImageView.frame.size.height, _TextWidth - 8, _PassHeight);
    _GiftPushWireLabel.frame = CGRectMake(10, _MainLabel.frame.origin.y + _MainLabel.frame.size.height + 8, _TextWidth - 10, 1);
    _GiftPresentToOther.frame = _MainImageView.bounds;
    [self.GiftPresentToOther addTarget:self action:@selector(buttonPresentAction) forControlEvents:UIControlEventTouchUpInside];
    
    [_MainImageView setImageWithURL:[NSURL URLWithString:[model.photo objectForKey:@"path"]]];
    _MainLabel.text = model.msg;
    
    self.GiftPassModel = model;
    if ([model.source_link containsString:@"taobao"] ) {
        NSLog(@"发现链接");
        _GiftPushJumpButton.frame = CGRectMake(_TextWidth - 100, _GiftPushWireLabel.frame.origin.y + _GiftPushWireLabel.frame.size.height + 13, 80, 30);
        [self.GiftPushJumpButton addTarget:self action:@selector(JumpWebAction) forControlEvents:UIControlEventTouchUpInside];
        self.GiftPushJumpButton.backgroundColor = RGBACOLOR(233, 53, 59, 1);
        self.ButtonWord = model.source_link;
        [self.GiftPushJumpButton setTitle:@"去购物" forState:UIControlStateNormal];
        [self.GiftPushJumpButton setTintColor:[UIColor whiteColor]];
        
        self.GiftPushTaobaoImageView.frame = CGRectMake(20, self.GiftPushJumpButton.frame.origin.y, 30, 30);
        
        self.GiftPushMoneyLabel.frame = CGRectMake(self.GiftPushTaobaoImageView.frame.origin.x + self.GiftPushTaobaoImageView.frame.size.width + 10, self.GiftPushTaobaoImageView.frame.origin.y, 200, 30);
        
        self.GiftPushTaobaoImageView.image = [UIImage imageNamed:@"iconfont-taobao-2.png"];
        
        self.GiftPushMoneyLabel.text = [@"￥" stringByAppendingString:[NSString stringWithFormat:@"%@", [model.item objectForKey:@"price"]]];
        self.GiftPushMoneyLabel.textColor = RGBACOLOR(233, 53, 59, 1);
    } else if ([model.source_link containsString:@"weibo"]) {
        _GiftPushJumpButton.frame = CGRectMake(_TextWidth - 100, _GiftPushWireLabel.frame.origin.y + _GiftPushWireLabel.frame.size.height + 13, 80, 30);
        [self.GiftPushJumpButton addTarget:self action:@selector(JumpWebAction) forControlEvents:UIControlEventTouchUpInside];
        self.GiftPushJumpButton.backgroundColor = RGBACOLOR(120, 194, 76, 1);
        self.ButtonWord = model.source_link;
        [self.GiftPushJumpButton setTitle:@"去微博" forState:UIControlStateNormal];
        [self.GiftPushJumpButton setTintColor:[UIColor whiteColor]];
        
        self.GiftPushTaobaoImageView.frame = CGRectMake(20, self.GiftPushJumpButton.frame.origin.y, 30, 30);
        self.GiftPushTaobaoImageView.image = [UIImage imageNamed:@"iconfont-weibo.png"];
        
    }
    
    
}
- (void)buttonPresentAction
{
    
    [self.delegate didSelectButton:self.GiftPassModel];

}

- (void)JumpWebAction
{

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:self.ButtonWord]];
}


@end
